package org.come.baitan;

import com.tool.Stall.Commodity;
import com.tool.Stall.Stall;
import com.tool.Stall.StallBean;
import com.tool.btn.goodbtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import org.come.Frame.ZhuFrame;
import org.come.bean.LoginResult;
import org.come.entity.Goodstable;
import org.come.entity.RoleSummoning;
import org.come.mouslisten.ChoseGoodsStallMouslisten;
import org.come.mouslisten.GoodsMouslisten;
import org.come.until.*;

import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.font.FontRenderContext;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D;
import java.awt.image.ImageObserver;
import java.math.BigDecimal;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 式
 * @version 1.0
 * @project test1
 * @description 摆摊界面
 * @date 2024/1/28 11:50:12
 */
public class BaiTanJpanel extends JPanel {
    public ImageIcon back=new ImageIcon("inkImg/btsg/摆摊上架界面.png");
    public ImageIcon back1=new ImageIcon("inkImg/btsg/收购设置界面.png");
    public ImageIcon back2=new ImageIcon("inkImg/btsg/交易记录界面.png");
    ImageIcon baise = new ImageIcon("inkImg/btsg/border_quack.png");//白框
    ImageIcon hongse = new ImageIcon("inkImg/btsg/ss231.png");
    private JScrollPane jScrollPane;

    private JTree jTree;
    public static Stall Stall;
    boolean shoptext=false;
    public long danjia=0;
    public long zongjia=0;
    public long xianjin=0;
    public int xz=-1;
    public JTextField  pice;
    public JTextField  shuliang;
    public JTextField  name;
    public  long nub=0;
    public BaiTanBtn shangjia;
    public BaiTanBtn changeNameBtn;
    public int c=-1;
    public int goodPosition=0;
    private Commodity commodity;
    private JLabel labpettrade;
    public  BaiTanBtn[] xuanxiangka=new BaiTanBtn[3];
    public int id=0;
    public goodbtn[] pack=new goodbtn[6];
    public int packid=0;
    public GoodsMouslisten[] goodsMouslistens=new GoodsMouslisten[24];
    public   JLabel[] GoodsListLabel=new JLabel[24];
    public ImageIcon good;
    public Goodstable goodstable;
    public BaiTanBtn pet;
    public BaiTanBtn lingbao;
    public DefaultListModel<String> modelname;
    public JList<String> listEquipment;
    public Color fontcolor;
    public JScrollPane jScrollPane1;
    public JLabel[] PetsListLabel;
    private JLabel labpettradedi;
    public JLabel[] PetsListLabeldi;
    public RoleSummoning petxz;
    public JPanel petlist;
    public Map<RoleSummoning,ShouGou>petrolesulist=new HashMap<>();
    public Map<Goodstable,ShouGou>goodstableList=new HashMap<>();
    public int  index=-1;
    private static DefaultMutableTreeNode top;
    public static boolean showAll=true;
    public Map<Goodstable,ShouGou> shougou=new HashMap<>();
    public JPanel goods=new JPanel();
    public BaiTanBtn shoushoubtn;
    public BaiTanBtn baitan;
    public JScrollPane goumaijilu;
    public goumaijilu goumaijilujpanel=new goumaijilu(new ArrayList<>());
    public JScrollPane shougoujilu;
    public goumaijilu shougoujilujpanel=new goumaijilu(new ArrayList<>());
    public BaiTanBtn fenxiang;
    public Stall getStall() {
        if (this.Stall == null) {
            this.Stall = new Stall(RoleData.getRoleData().getLoginResult());
        }
        return this.Stall;
    }
    public BaiTanJpanel(){
        this.setPreferredSize(new Dimension(688, 488));
        this.setLayout(null);
        this.setOpaque(false);

        {
            xuanxiangka[0]=new BaiTanBtn("skin/8100226/rg-bt/出售-2.png",1, 0,this);
            xuanxiangka[0].setBounds(50,20,85,33);
            this.add(xuanxiangka[0]);
		/*	xuanxiangka[1]=new BaiTanBtn("inkImg/btsg/上方按钮-未选中.png",1, UIUtils.HLW,UIUtils.Black,"收购",this,1);
			xuanxiangka[1].setBounds(50+88,20,85,33);
			this.add(xuanxiangka[1]);
			xuanxiangka[2]=new BaiTanBtn("inkImg/btsg/上方按钮-未选中.png",1, UIUtils.HLW,UIUtils.Black,"交易记录",this,2);
			xuanxiangka[2].setBounds(50+88*2,20,85,33);
			this.add(xuanxiangka[2]);*/
            xuanxiangka[1]=new BaiTanBtn("skin/8100226/rg-bt/收购-4.png",1,1,this);
            xuanxiangka[1].setBounds(50+88,20,85,33);
            this.add(xuanxiangka[1]);
            xuanxiangka[2]=new BaiTanBtn("skin/8100226/rg-bt/交易记录-5.png",1, 2,this);
            xuanxiangka[2].setBounds(50+88*2,20,85,33);
            this.add(xuanxiangka[2]);
        }
        for (int i=0;i<6;i++){
            pack[i]=new goodbtn("inkImg/btsg/pack"+i+".png",1,this,i);
            pack[i].setBounds(362,67+i*33,35,31);
            this.add(pack[i]);
        }
        int i=0;
        while (i < 24) {
            final int row = i % 6;
            final int col = i / 6;
            final int[] arr = { 55 + row * 51, 68 + col * 51 };
            GoodsListLabel[i] = new JLabel();
            this.goodsMouslistens[i] = new GoodsMouslisten(i, this, arr);
            GoodsListLabel[i].addMouseListener((MouseListener)this.goodsMouslistens[i]);
            GoodsListLabel[i].setBounds(55 + row * 51, 68 + col * 51, 50, 50);
            this.add((Component)GoodsListLabel[i]);
            ++i;
        }
        (this.pice = new JTextField () {
            Image image = back.getImage();
            Image grayImage = GrayFilter.createDisabledImage(this.image);

            {
                this.setOpaque(false);
            }

            @Override
            public void paint(final Graphics g) {
                //g.drawImage(this.grayImage, 0, 0, (ImageObserver)this);
                super.paint(g);
            }
        }).setBounds(472,210,130,20);
        this.pice.setForeground(Color.white);
        this.pice.setBackground(Color.WHITE);
        this.pice.setBorder(BorderFactory.createEmptyBorder());
        this.pice.setCaretColor(Color.WHITE);
        this.pice.setOpaque(false);
        this.pice.setFont(new Font("宋体", 1, 14));
        this.add((Component)this.pice);
        (this.shuliang = new JTextField () {

            {
                this.setOpaque(false);
            }

            @Override
            public void paint(final Graphics g) {

                super.paint(g);
            }
        }).setBounds(486,165,70,20);
        this.shuliang.setForeground(Color.white);
        this.shuliang.setBackground(Color.WHITE);
        this.shuliang.setBorder(BorderFactory.createEmptyBorder());
        this.shuliang.setCaretColor(Color.WHITE);
        this.shuliang.setOpaque(false);
        this.shuliang.setHorizontalAlignment(JTextField.CENTER);
        this.shuliang.setFont(new Font("宋体", 1, 13));
        this.add(shuliang);
        allowNumericOnly(shuliang);
        allowNumericOnly(pice);
        (this.name = new JTextField () {

            {
                this.setOpaque(false);
            }

            @Override
            public void paint(final Graphics g) {

                super.paint(g);
            }
        }).setBounds(346,20,100,20);
        this.name.setForeground(Color.WHITE);
        this.name.setBackground(Color.WHITE);
        this.name.setBorder(BorderFactory.createEmptyBorder());
        this.name.setCaretColor(Color.WHITE);
        this.name.setOpaque(false);
        this.name.setFont(new Font("宋体", Font.PLAIN, 13));
        this.name.setText(RoleData.getRoleData().getLoginResult().getRolename()+"的摊位");
        this.add(name);
        changeNameBtn = new BaiTanBtn("inkImg/button/B408.png",1, new Font("宋体", Font.PLAIN, 12), UIUtils.White, "更改",this,107);
        changeNameBtn.setBounds(430, 22, 34, 17);
        this.add(changeNameBtn);
        shangjia=new BaiTanBtn("inkImg/btsg/上架更新按钮.png",1,UIUtils.HLW,UIUtils.Black,"上架",this,10);
        shangjia.setBounds(480,320,79,25);
        this.add(shangjia);
        pet=new BaiTanBtn("skin/8100226/rg-bt/灵宝-9.png",1,11,this);
        pet.setBounds(55,284,63,25);
        this.add(pet);
        lingbao=new BaiTanBtn("skin/8100226/rg-bt/宠物-7.png",1,12,this);
        lingbao.setBounds(120,284,63,25);
        this.add(lingbao);

        this.modelname = new DefaultListModel();
        modelname.addElement("我的收购");
        modelname.addElement("作坊");
        modelname.addElement("召唤兽");
        modelname.addElement("打造");
        modelname.addElement("生产系统");
        (this.listEquipment = new JList()).setOpaque(false);
        this.listEquipment.setSelectionBackground(new Color(33, 42, 52));
        this.fontcolor = Color.GREEN;
        this.listEquipment.setSelectionForeground(this.fontcolor);
        this.listEquipment.setForeground(this.fontcolor);
        this.listEquipment.setFont(new Font("微软雅黑", 1, 14));
        this.listEquipment.setBackground(UIUtils.Color_BACK);
        this.listEquipment.setModel(this.modelname);
        this.listEquipment.setCellRenderer(new myRenderer(this));
        this.listEquipment.addMouseListener(new MouseListener() {
            @Override
            public void mouseReleased(final MouseEvent e) {
            }

            @Override
            public void mousePressed(final MouseEvent e) {
                if (listEquipment.getSelectedIndex() != -1) {
                    index=listEquipment.getSelectedIndex();
                    String name=modelname.get(index);
                    Goodstable goodstable=UserMessUntil.getgoodstablefromname(name);
                    if (goodstable==null){
                        ZhuFrame.getZhuJpanel().addPrompt("该物品不存在，请联系管理员！#0");
                    }
                }
            }

            @Override
            public void mouseExited(final MouseEvent e) {
            }

            @Override
            public void mouseEntered(final MouseEvent e) {

            }

            @Override
            public void mouseClicked(final MouseEvent e) {
            }
        });
        (this.jScrollPane1 = new JScrollPane((Component)this.listEquipment)).setVerticalScrollBarPolicy(22);
        this.jScrollPane1.getVerticalScrollBar().setUI(new SrcollPanelUI());
        this.jScrollPane1.getViewport().setOpaque(false);
        this.jScrollPane1.setOpaque(false);
        this.jScrollPane1.setBounds(460, 75, 170, 175);
        this.jScrollPane1.setBorder(null);
        this.jScrollPane1.setHorizontalScrollBarPolicy(31);
        this.add((Component)this.jScrollPane1);

        this.PetsListLabel = new JLabel[6];
        this.PetsListLabeldi = new JLabel[6];
        int j=0;
        while (j < 6) {
            final int[] arr = { 23 + j * 57, 263 };
            (this.PetsListLabel[j] = new JLabel()).addMouseListener(new ChoseGoodsStallMouslisten(j, 1, this, arr));
            this.PetsListLabel[j].setBounds(23 + j * 57+40, 251+66, 35, 35);
            this.add((Component)this.PetsListLabel[j]);
            (this.PetsListLabeldi[j] = new JLabel()).addMouseListener(new ChoseGoodsStallMouslisten(j, 1, this, arr));
            this.PetsListLabeldi[j].setBounds(15 + j * 57+42, 252+60, 45, 45);
            this.add((Component)this.PetsListLabeldi[j]);
            ++j;
        }
        (this.labpettrade = new JLabel("", 0)).setBounds(44, 326, 66, 66);
        this.add((Component)this.labpettrade);
        (this.labpettradedi = new JLabel("", 0)).setBounds(44, 326, 66, 66);
        this.add((Component)this.labpettradedi);
        this.labpettrade.setBounds(487, 96, 66, 66);
        this.labpettradedi.setBounds(487, 96, 66, 66);
        AccessBaiTanMsgUntil.showSuitMethod(top = new DefaultMutableTreeNode(""),showAll);
        (this.jTree = new JTree((TreeNode)top)).setOpaque(false);
        this.jTree.putClientProperty("JTree.lineStyle", "None");
        ((BasicTreeUI)this.jTree.getUI()).setLeftChildIndent(0);
        final DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer() {
            @Override
            public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
                final DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
                super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
                if (node.getLevel() == 2) {

                }
                return this;
            }
        };
        cellRenderer.setLeafIcon(null);
        try {
            cellRenderer.setOpenIcon((Icon)CutButtonImage.cuts("inkImg/button/B108.png")[0]);
            cellRenderer.setClosedIcon((Icon)CutButtonImage.cuts("inkImg/button/B109.png")[0]);
        }
        catch (Exception e1) {
            e1.printStackTrace();
        }
        cellRenderer.setFont(new Font("宋体", 0, 14));
        cellRenderer.setBackgroundNonSelectionColor(new Color(0, 0, 0, 0));
        cellRenderer.setBackgroundSelectionColor(new Color(99, 93, 90));
        cellRenderer.setBorderSelectionColor(new Color(0, 0, 0, 0));
        cellRenderer.setTextNonSelectionColor(Color.white);
        cellRenderer.setTextSelectionColor(Color.white);
        this.jTree.setCellRenderer((TreeCellRenderer)cellRenderer);
        this.jTree.setRootVisible(false);
        this.jTree.setRowHeight(20);
        this.jTree.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e)) {
                    final TreePath path = jTree.getSelectionPath();
                    if (path != null) {
                        if (jTree.isExpanded(path)) {
                            jTree.collapsePath(path);
                        }
                        else {
                            jTree.expandPath(path);
                        }
                    }
                }
            }
        });
        this.jTree.addTreeSelectionListener(new TreeSelectionListener() {
            @Override
            public void valueChanged(final TreeSelectionEvent e) {
                final JTree tree = (JTree)e.getSource();
                final DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                if (selectionNode == null) {
                    jScrollPane1.setViewportView(null);
                    return;
                }
                else {
                    final String nodeName = selectionNode.toString();
                    if (selectionNode.isLeaf()) {
                        modelname.clear();
                        shoushoubtn.setText("收购");
                        if (nodeName.equals("我的收购")){
                            for (Goodstable goodstable: shougou.keySet()){
                                modelname.addElement(goodstable.getGoodsname());
                            }
                            shoushoubtn.setText("取消");

						}else if (nodeName.equals("培养物品")){
							modelname.addElement("凝魂珠");
							modelname.addElement("灵犀丹");
                            modelname.addElement("龙之骨");
							modelname.addElement("神兽碎片");
							modelname.addElement("千年魂石");
							modelname.addElement("隐月神石");
							modelname.addElement("玄铁晶石");
                            modelname.addElement("超级龙之骨");
                            modelname.addElement("伐骨洗髓丹");
							modelname.addElement("终极亲密丹");
							modelname.addElement("珍稀神兽丹");
							modelname.addElement("化形丹·神");
							modelname.addElement("超级元气丹");
							modelname.addElement("超级变色丹");
							modelname.addElement("高级聚魄丹");
							modelname.addElement("神兽飞升丹");
                            modelname.addElement("超级伐骨洗髓丹");
							modelname.addElement("召唤兽进阶丹");
							modelname.addElement("比斗奖章礼包");
							modelname.addElement("神兽飞升丹");
							modelname.addElement("鎏金宝鉴碎片");
							modelname.addElement("珍稀神兽碎片");
							modelname.addElement("幻肤神兽碎片");
							modelname.addElement("幻肤神兽魂珠");
							modelname.addElement("神兽兑换令");
							modelname.addElement("神兽兑换证");
							modelname.addElement("五六珍稀升星碎片");
							modelname.addElement("新手宝宝升星碎片");
							modelname.addElement("幻神宝宝升星碎片");
							modelname.addElement("老版神兽升星碎片");
							modelname.addElement("普通宝宝升星碎片");
							modelname.addElement("天书鎏金升星碎片");
							modelname.addElement("高级守护升星碎片");
							modelname.addElement("龙涎丸宝宝升星碎片");


						}else if (nodeName.equals("矿石")){
							modelname.addElement("补天神石");
							modelname.addElement("六魂之玉");
							modelname.addElement("无量琉璃");


						}else if (nodeName.equals("培养物品(灵宝)")){
							modelname.addElement("灵宝要诀");
							modelname.addElement("灵宝天威印");
							modelname.addElement("灵宝诸天印");
							modelname.addElement("高级玄灵之矿");
							modelname.addElement("高级乾灵聚元丹");


						}else if (nodeName.equals("材料")){
							modelname.addElement("奖券");
							modelname.addElement("翠玉");
							modelname.addElement("香火");
							modelname.addElement("落魄沙");
							modelname.addElement("神行符");
							modelname.addElement("红宝石");
							modelname.addElement("绿宝石");
							modelname.addElement("橙宝石");
							modelname.addElement("紫宝石");
							modelname.addElement("蓝宝石");
							modelname.addElement("物资盲盒");
							modelname.addElement("乾坤丹");
							modelname.addElement("九天玄玉");
							modelname.addElement("翅膀精华");
							modelname.addElement("珍稀人参果");
							modelname.addElement("法门修炼丹");
							modelname.addElement("翅膀品质石");
							modelname.addElement("翅膀重铸石");
							modelname.addElement("翅膀炼化石");
							modelname.addElement("浑天石");
							modelname.addElement("神·帽子兑换珠");
							modelname.addElement("神·衣服兑换珠");
							modelname.addElement("神·鞋子兑换珠");
							modelname.addElement("神·项链兑换珠");
							modelname.addElement("终极技能修炼丹");

						}else if (nodeName.equals("坐骑")){
							modelname.addElement("筋骨提气丸");
							modelname.addElement("超级坐骑经验丹");
							modelname.addElement("超级坐骑熟练丹");
							modelname.addElement("守护石");
							modelname.addElement("灵元晶");

						}else if (nodeName.equals("技能书")){
							modelname.addElement("天籁梵音");
							modelname.addElement("风火燎原");
							modelname.addElement("舍身取义");
							modelname.addElement("取之有道");
							modelname.addElement("殃及池鱼");
							modelname.addElement("妙手回春");
							modelname.addElement("春意盎然");
							modelname.addElement("进退自如");
							modelname.addElement("分花拂柳");
							modelname.addElement("神出鬼没");
							modelname.addElement("鬼神莫测");
							modelname.addElement("大隐于朝");
							modelname.addElement("吉人天相");
							modelname.addElement("高级清明术");
							modelname.addElement("高级脱困术");
							modelname.addElement("高级强心术");
							modelname.addElement("义之金叶神");
							modelname.addElement("信之土叶神");
							modelname.addElement("高级帐饮东都");
							modelname.addElement("高级源泉万斛");
							modelname.addElement("高级神工鬼力");
							modelname.addElement("高级倍道兼行");
							modelname.addElement("高级分裂攻击");
							modelname.addElement("？？？");

                        }
                        jScrollPane1.setVisible(true);

                        index=-1;
                    }
                    else {


                        jScrollPane1.setVisible(false);
                        modelname.clear();
                        index=-1;
                    }
                    return;
                }
            }
        });
        (this.jScrollPane = new JScrollPane((Component)this.jTree)).setVerticalScrollBarPolicy(22);
        this.jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
        this.jScrollPane.getViewport().setOpaque(false);
        this.jScrollPane.setOpaque(false);
        this.jScrollPane.setBounds(332, 75, 130, 208);
        this.jScrollPane.setBorder(BorderFactory.createEmptyBorder());
        this.jScrollPane.setHorizontalScrollBarPolicy(31);
        this.add((Component)this.jScrollPane);
        shoushoubtn=new BaiTanBtn("inkImg/btsg/搜索按钮.png",1,UIUtils.HLW,UIUtils.Black,"收购",this,13);
        shoushoubtn.setVisible(false);
        shoushoubtn.setBounds(550,350,59,25);
        this.add(shoushoubtn);
        baitan=new BaiTanBtn("inkImg/btsg/搜索按钮.png",1,UIUtils.HLW,UIUtils.Black,"摆摊",this,14);
        baitan.setVisible(false);
        baitan.setBounds(488,350,59,25);
        this.add(baitan);
        (this.goumaijilu = new JScrollPane((Component)this.goumaijilujpanel)).setVerticalScrollBarPolicy(22);
        this.goumaijilu.getVerticalScrollBar().setUI(new SrcollPanelUI());
        this.goumaijilu.getViewport().setOpaque(false);
        this.goumaijilu.setOpaque(false);
        this.goumaijilu.setBounds(45, 75, 303, 280);
        this.goumaijilu.setBorder(null);
        this.goumaijilu.setHorizontalScrollBarPolicy(31);
        this.add((Component)this.goumaijilu);
        (this.shougoujilu = new JScrollPane((Component)this.shougoujilujpanel)).setVerticalScrollBarPolicy(22);
        this.shougoujilu.getVerticalScrollBar().setUI(new SrcollPanelUI());
        this.shougoujilu.getViewport().setOpaque(false);
        this.shougoujilu.setOpaque(false);
        this.shougoujilu.setBounds(45+305, 75, 303, 280);
        this.shougoujilu.setBorder(null);
        this.shougoujilu.setHorizontalScrollBarPolicy(31);
        this.add((Component)this.shougoujilu);
        Font plainFont = new Font("宋体", Font.PLAIN, 12); // 字体名称、样式、大小
        fenxiang=new BaiTanBtn("inkImg/newbutton/B34.png",1,plainFont,UIUtils.White,"分享摊位",this,106);
//        shareBtn = new SpotPublishBtn("inkImg/newbutton/B34.png",1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT2, "分享摊位",102,this);
        fenxiang.setVisible(false);
        fenxiang.setBounds(50,400,75,26);
        this.add(fenxiang);
    }
    public void init(){
        id=0;
        shoushoubtn.setVisible(false);
        baitan.setVisible(true);
        if (getStall().getId()>=1){
            baitan.setText("收摊");
        }else baitan.setText("摆摊");


    }
    public void setPice(boolean l){
        pice.setVisible(l);
        shuliang.setVisible(l);
        pice.setText("0");
        shuliang.setText("0");
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
         changeNameBtn.setBounds(470, 22, 34, 17);
        jScrollPane.setVisible(false);
        shougoujilu.setVisible(false);
        goumaijilu.setVisible(false);
        if (id!=0){
            for (int i=0;i<6;i++){
                pack[i].setVisible(false);
                PetsListLabel[i].setVisible(false);
                PetsListLabeldi[i].setVisible(false);
            }
            shangjia.setVisible(false);
            pet.setVisible(false);
            lingbao.setVisible(false);
            labpettrade.setVisible(false);
            labpettradedi.setVisible(false);
        }

        if (id!=1){
            jScrollPane1.setVisible(false);
            index=-1;
        }
        fenxiang.setVisible(false);
        final LoginResult login = RoleData.getRoleData().getLoginResult();
        switch (id){
            case 0:
                g.drawImage(back.getImage(),0,0,659,439,null);
                pice.setBounds(472,210,130,20);
                shuliang.setBounds(486,165,70,20);
                for (int i=0;i<6;i++){
                    pack[i].setVisible(true);
                    PetsListLabel[i].setVisible(true);
                    PetsListLabeldi[i].setVisible(true);
                }
                fenxiang.setBounds(50,380,75,26);
                fenxiang.setVisible(true);
                shangjia.setVisible(true);
                GoodsListFromServerUntil.draw(g, 55, 68);
                pet.setVisible(true);
                lingbao.setVisible(true);
                labpettrade.setVisible(true);
                labpettradedi.setVisible(true);
                if (this.shoptext) {

                    final int shop_x = this.goodPosition % 6;
                    final int shop_y = this.goodPosition / 6;
                    if (!p)
                        g.drawImage(baise.getImage(), 55 + shop_x * 51, 68 + shop_y * 51, (ImageObserver)this);
                    else g.drawImage(baise.getImage(), 53 + shop_x * 57, 310 + shop_y * 51, (ImageObserver)this);
                }

                Util.drawPrice(g, login.getGold(), 475, 288);
                if (shuliang.getText()==null||shuliang.getText().equals("")){
                    nub=0;
                    shuliang.setText(0+"");
                }else{
                    int num = goodstable == null ? 0 : goodstable.getUsetime();
                    nub=Integer.parseInt(shuliang.getText());
                    nub=Math.min(num,nub);
                    shuliang.setText(nub+"");
                }
                if (petxz!=null){
                    shuliang.setText(1+"");
                }
                if (pice.getText()==null||pice.getText().equals("")){
                    danjia=0;
                    pice.setText(0+"");
                }else {danjia= Long.parseLong(pice.getText());
                    pice.setText(danjia+"");}


                zongjia=danjia*Long.parseLong(shuliang.getText());
                Util.drawPrice(g, new BigDecimal(zongjia), 475, 260);

                if (goodstable!=null&&petxz==null){
                    good=GoodsListFromServerUntil.imgpath(goodstable.getSkin());
                    g.drawImage(good.getImage(), 495, 105, 48, 48, null);
                    if (goodstableList.containsKey(goodstable)){
                        shangjia.setText("下架");
                        pice.setText(goodstableList.get(goodstable).pice+"");
                        shuliang.setText(goodstableList.get(goodstable).num+"");
                        zongjia=danjia*Long.parseLong(shuliang.getText());
                        Util.drawPrice(g, new BigDecimal(zongjia), 475, 260);
                    }else shangjia.setText("上架");
                }else if (petxz!=null&&petrolesulist.containsKey(petxz)){
                    shangjia.setText("下架");
                    pice.setText(petrolesulist.get(petxz).pice+"");
                }else shangjia.setText("上架");
                break;
            case 1:
                g.drawImage(back1.getImage(),0,0,659,439,null);
                jScrollPane.setVisible(true);
                pice.setBounds(435,295,100,20);
                shuliang.setBounds(315,350,100,20);
                //jScrollPane.setBounds(340,75,290,170);
                //	jScrollPane1.setVisible(true);
                if (shuliang.getText()==null||shuliang.getText().equals("")){
                    nub=0;
                    shuliang.setText(0+"");
                }else {
                    nub= Long.parseLong(shuliang.getText());
                    shuliang.setText(nub+"");
                }

                if (pice.getText()==null||pice.getText().equals("")){
                    danjia=0;
                    pice.setText(0+"");
                }else {danjia= Long.parseLong(pice.getText());
                    pice.setText(danjia+"");
                }
                zongjia=danjia*nub;
                //final LoginResult login = RoleData.getRoleData().getLoginResult();
                Util.drawPrice(g, login.getGold(), 435, 365);
                if(index!=-1){
                    String name=modelname.get(index);
                    Goodstable goodstable=UserMessUntil.getgoodstablefromname(name);
                    if (goodstable!=null){
                        good=GoodsListFromServerUntil.imgpath(goodstable.getSkin());
                        g.drawImage(good.getImage(), 340, 295, 48, 48, null);
                        Util.drawPrice(g, new BigDecimal(zongjia), 435, 338);
                    }
                }
                if (shougou.size()>0){
                    int k=0;
                    for (Goodstable goodstable:shougou.keySet()){
                        g.setColor(Color.white);
                        g.drawString(goodstable.getGoodsname(),45,90+k*22);
                        g.drawString(shougou.get(goodstable).num+"",160,90+k*22);
                        Util.drawPrice(g,new BigDecimal(shougou.get(goodstable).num*shougou.get(goodstable).pice),250,90+k*22);
                        k++;
                    }
                }

                break;
            case 2:
                g.drawImage(back2.getImage(),0,0,688,488,null);
                shougoujilu.setVisible(true);
                goumaijilu.setVisible(true);
                break;
        }
	/*int j=0;
	while (j < 6) {

		this.PetsListLabel[j].setBounds(23 + j * 57+40, 251+66, 35, 35);


		this.PetsListLabeldi[j].setBounds(15 + j * 57+42, 252+60, 45, 45);

		++j;
	}*/


    }
    public boolean p=false;
    public void PaintingText(final int goodPosition,boolean pet) {
        this.goodPosition = goodPosition;
        this.shoptext = true;
        p=pet;

    }
    public void ClearText() {
        this.shoptext = false;
    }
    public void xuanzhong(final Goodstable goodstable, final int shopPlace) {
        if (goodstable == null) {
            if (xz != -1) {
                GoodsListLabel[xz].setBorder(null);
            }
            xz = -1;
        }
        else {
            if (xz != -1) {
                GoodsListLabel[xz].setBorder(null);
            }
            xz = shopPlace;
            c=xz;
            GoodsListLabel[xz].setBorder(BorderFactory.createLineBorder(Color.red));
            if (goodstable!=this.goodstable){
                nub=1;
                shuliang.setText(nub+"");
                pice.setText(0+"");

            }
            this.goodstable=goodstable;
            petxz=null;
            labpettrade.setIcon(null);
            labpettradedi.setIcon(null);

        }
    }
    public goodbtn[] getPack() {
        return pack;
    }

    public void setPack(goodbtn[] pack) {
        this.pack = pack;
    }
    public static void allowNumericOnly(JTextField textField) {
        AbstractDocument doc = (AbstractDocument) textField.getDocument();
        doc.setDocumentFilter(new DocumentFilter() {
            @Override
            public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
                    throws BadLocationException {
                if (isNumeric(string)) {
                    super.insertString(fb, offset, string, attr);
                }
            }

            @Override
            public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
                    throws BadLocationException {
                if (isNumeric(text)) {
                    super.replace(fb, offset, length, text, attrs);
                }
            }

            private boolean isNumeric(String text) {


                return text.matches("\\d*");
            }
        });
    }

    public DefaultListModel<String> getModelname() {
        return modelname;
    }

    public void setModelname(DefaultListModel<String> modelname) {
        this.modelname = modelname;
    }
    public void XZBuy( final RoleSummoning pet) {

        if (pet != null) {
            (this.commodity = new Commodity()).setPet(pet);
            this.commodity.setMoney(1L);
            this.commodity.setCurrency("金钱");
            int j = 0;

            {
                final ImageIcon img = new ImageIcon("img/newHead/p" + commodity.getPet().getSummoningskin() + ".png");
                img.setImage(img.getImage().getScaledInstance(65, 65, 10));
                this.labpettrade.setIcon((Icon)img);
                final ImageIcon path1 = CutButtonImage.getImage("inkimg/danxin/ss291.png", 45, 45);
                path1.setImage(path1.getImage().getScaledInstance(45, 45, 10));
                this.labpettradedi.setIcon((Icon)path1);
                shuliang.setText(1+"");
                petxz=pet;
            }


        }
    }

    public Commodity getCommodity() {
        return commodity;
    }

    public void setCommodity(Commodity commodity) {
        this.commodity = commodity;
    }
    public void CId(final StallBean bean) {
        if (this.Stall == null) {
            this.Stall = new Stall(RoleData.getRoleData().getLoginResult());
        }
        this.Stall.setId(bean.getId());
        this.Stall.setState(bean.getState());
        if (bean.getState() == StallBean.NO) {
            this.Stall.setId(0);
            int i = 0;
            while (i < 24) {
                this.Stall.getGoodstables()[i] = null;
                this.GoodsListLabel[i].setIcon(null);
                i++;
            }
            int j = 0;
            while (j < 6) {
                this.Stall.getPets()[j] = null;
                this.PetsListLabel[j].setIcon(null);
                this.PetsListLabeldi[j].setIcon(null);
                ++j;
            }
            Stall.getShouGous().clear();
            shougou.clear();
            goodstableList.clear();
            petrolesulist.clear();
            this.commodity = null;
            this.labpettrade.setIcon(null);
            FormsManagement.HideForm(15);
            FormsManagement.HideForm(16);
        }
    }
    public void updata(Stall stall){
        this.Stall=stall;
        for (int i=0;i<=stall.getGoodstables().length-1;i++){
            if (stall.getGoodstables()[i]==null)continue;
            Goodstable goodstable=stall.getGoodstables()[i].getGood();
            for (Goodstable g:goodstableList.keySet()){
                if (goodstable.getRgid().longValue()==g.getRgid().longValue()){
                    g.goodxh(Math.toIntExact(goodstableList.get(g).num - stall.getGoodstables()[i].getNumber()));
                    goodstableList.get(g).num=stall.getGoodstables()[i].getNumber();
                    if (goodstableList.get(g).num<=0){
                        goodstableList.remove(g);
                        goodstable.setUsetime(0);
                        GoodsListFromServerUntil.shouhu(goodstable.getRgid().intValue());
                    }
                }
            }
        }
        List<RoleSummoning>petlist=new ArrayList<>();
        for (int i=0;i<=stall.getPets().length-1;i++){
            if (stall.getPets()[i]==null)continue;
            RoleSummoning goodstable=stall.getPets()[i].getPet();
            for (RoleSummoning g:petrolesulist.keySet()){
                if (goodstable.getSid().longValue()==g.getSid().longValue()){
                    petrolesulist.get(g).num=stall.getPets()[i].getNumber();
                    if (petrolesulist.get(g).num<=0){
                        petlist.add(g);
                        UserMessUntil.getPetListTable().remove(g);
                        this.PetsListLabel[i].setIcon(null);
                        this.PetsListLabeldi[i].setIcon(null);

                    }
                }
            }
        }
        for (RoleSummoning roleSummoning:petlist){
            petrolesulist.remove(roleSummoning);
        }
        List<Goodstable>shouGouList=new ArrayList<>();
        for (ShouGou shouGou:Stall.getShouGous()){
            if (shouGou.num<=0){
                shouGouList.add(shouGou.goodstable);
            }else {
                for (Goodstable goodstable1:shougou.keySet()){
                    if (goodstable1.getGoodsid().longValue()==shouGou.getGoodstable().getGoodsid().longValue()){
                        shougou.get(goodstable1).setNum(shouGou.num);
                    }
                }



            }
        }
        for (Goodstable goodstable1:shouGouList){
            shougou.remove(goodstable1);
        }
    }

    public static class goumaijilu extends JPanel{
        public List<Record>records;
        goumaijilu(List<Record>records){
            this.records=records;
            this.setOpaque(false);
            this.setPreferredSize(new Dimension(303,280));
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;

            // 设置字体
            Font font = new Font("宋体", Font.PLAIN, 15);

            g2d.setFont(font);
            g2d.setColor(Color.yellow);
            // 设置绘制区域
            int width = getWidth();
            int height = getHeight();
            int margin = 10; // 你可以调整边距
            Rectangle2D rect = new Rectangle2D.Double(margin, margin, width - 2 * margin, height - 2 * margin);

            // 绘制文本
            float y = (float) rect.getY() + font.getSize();
            for (Record record : records) {
                String text = recordToString(record);
                //g.drawString(text,0,10);
                drawWrappedText(g2d, text, rect.getX()-10, y-20, rect.getWidth());
                y += font.getSize() * 2.2; // 你可以调整行间距
            }
            repaint();
        }
        private void drawWrappedText(Graphics2D g2d, String text, double x, double y, double maxWidth) {
            FontRenderContext frc = g2d.getFontRenderContext();
            AttributedString attributedString = new AttributedString(text);
            attributedString.addAttribute(TextAttribute.FONT, g2d.getFont());

            AttributedCharacterIterator paragraph = attributedString.getIterator();
            LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(paragraph, frc);
            float drawPosY = (float) y;

            while (lineBreakMeasurer.getPosition() < paragraph.getEndIndex()) {
                TextLayout layout = lineBreakMeasurer.nextLayout((float) maxWidth);
                drawPosY += layout.getAscent();
                layout.draw(g2d, (float) x, drawPosY);
                drawPosY += layout.getDescent() + layout.getLeading();
            }
        }

        public List<Record> getRecords() {
            return records;
        }

        public void setRecords(List<Record> records) {
            this.records = records;
        }
    }
    public static Stall copyStall(LoginResult loginResult){
        Stall stall = new Stall(loginResult);
        stall.setId(BaiTanJpanel.Stall.getId());
        stall.setMapid(BaiTanJpanel.Stall.getMapid());
        stall.setRoleid(BaiTanJpanel.Stall.getRoleid());
        stall.setRole(BaiTanJpanel.Stall.getRole());
        stall.setState(BaiTanJpanel.Stall.getState());
        return stall;
    }
    public static String recordToString(Record record){

        if (record.getRecordType()==100){
            return "玩家"+record.getRoleid()+"花费了"+record.getText()+"购买了"+record.getGoodsum()+"个"+UserMessUntil.getgoodstable(new BigDecimal(record.getGoodsid())).getGoodsname()+"。"+"("+record.getRecordTime()+")";
        }else if (record.getRecordType()==101){
            return "店铺花费了"+record.getText()+"收购了玩家"+record.getRoleid()+record.getGoodsum()+"个"+UserMessUntil.getgoodstable(new BigDecimal(record.getGoodsid())).getGoodsname()+"。"+"("+record.getRecordTime()+")";
        }
        return null;
    }

   public String getStallName(){
        return name.getText();
   }
}


